package com.example.demo.mapper;

import com.example.demo.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {

    /**
     * 查询所有已存在的用户
     *
     * @return {@link User}
     */
    @Select("SELECT * FROM user")
    List<User> selectAllUsers();

    /**
     * 根账号查询用户是否数量
     *
     * @param account 账号
     * @return 已存在的用户数
     */
    @Select("SELECT COUNT(*) FROM user WHERE account = #{account}")
    int countUserByAccount(String account);

    /**
     * 插入用户注册信息
     *
     * @param user {@link User}
     * @return rs >1:插入成功 else:插入失败
     */
    @Insert("INSERT INTO user (account, password, sex, email, tel) values(#{account}, #{password}, #{sex}, #{email}, #{tel})")
    int insertUser(User user);


}
